package com.mc2.docapp.disabilityassessmenttool.utils;

import com.googlecode.openbeans.Introspector;
import com.googlecode.openbeans.PropertyDescriptor;
import com.mc2.docapp.disabilityassessmenttool.SampleExcelDTO;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Runt {
    public static void main(String[] args) throws Exception {
        System.out.println("javaSlangBeanProperties(SampleExcelDTO.class, new SampleExcelDTO(1, 2, \"c\", \"d\", new Date())) = " + javaSlangBeanProperties(SampleExcelDTO.class, new SampleExcelDTO(1, 2, "c", "d", new Date())));
    }

    public static Map<String, String> javaSlangBeanProperties(Class<SampleExcelDTO> h, Object bean) throws Exception {
        Map<String,String> map = new HashMap<String, String>();
        for (PropertyDescriptor propertyDescriptor :
                Introspector.getBeanInfo(h, Object.class).getPropertyDescriptors()) {
            map.put(propertyDescriptor.getReadMethod().getName(),propertyDescriptor.getReadMethod().invoke(bean).toString());
        }
        return map;
    }
}